package com.lancoo.znbkxx.teacher.widget

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.WindowManager
import android.widget.PopupWindow
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.adapter.EvenItemDecoration
import com.lancoo.znbkxx.teacher.adapter.StuNameAdapter
import com.lancoo.znbkxx.teacher.model.data.ValidStu
import com.lancoo.znbkxx.teacher.utils.DensityUtils

/**
 * @author : Admin
 * @date   : 2020/10/14
 * @desc   :
 */
class StuMenu(context: Context,
              data: MutableList<ValidStu>,
              listener: BaseQuickAdapter.OnItemClickListener) : PopupWindow(context) {
    init {
        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val mPopView = inflater.inflate(R.layout.popupwindow_stuname, null)
        val rv = mPopView.findViewById<RecyclerView>(R.id.rv)
        val adapter = StuNameAdapter(data)
        adapter.onItemClickListener = listener
        rv.layoutManager =
                GridLayoutManager(context,2)
        rv.addItemDecoration(
                EvenItemDecoration(
                        DensityUtils.dp2px(context, 10f),
                        2
                )
        )
        rv.adapter = adapter
        this.contentView = mPopView
        this.width = WindowManager.LayoutParams.WRAP_CONTENT
        this.height = DensityUtils.dp2px(context,450f)
        this.isOutsideTouchable = true
        this.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        this.isFocusable = true
        update()
    }
}